package com.chengn;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadPoolParam {

    public static void main(String[] args) {

        ThreadPoolExecutor executor = new ThreadPoolExecutor(1,
                1,
                1,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10),
                new ThreadPoolExecutor.CallerRunsPolicy());


        // 第一个参数 线程工厂测试 核心线程创建逻辑 main线程退出？
//        executor.execute(() -> {
//            System.out.println(1);
//        });
    }


    // 线程工厂
    static class MyThreadFactory implements ThreadFactory {

        static AtomicInteger prefixNum = new AtomicInteger(1);

        private static final String THREAD_PREFIX = "my-thread-";

        @Override
        public Thread newThread(Runnable r) {
            String s = THREAD_PREFIX + prefixNum.getAndAdd(1);
            Thread thread = new Thread(r, s);
            System.out.println("构造线程：" + s);

            return thread;
        }
    }

    // PriorityBlockingQueue 测试


}
